package org.tiger.netty.server.nio;

import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author lwl
 * @date 2020/10/9 9:01 下午
 */
public class NioTest9 {

	private static Logger logger = LoggerFactory.getLogger(NioStudyOne.class);

	public static void main(String[] args) throws Exception {

		String path = NioStudyOne.class.getClassLoader().getResource("").getPath().toString();

		logger.info("path:" + path);

		RandomAccessFile file = new RandomAccessFile(path + "niotest9.txt", "rw");
		FileChannel fileChannel = file.getChannel();
		MappedByteBuffer mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, 5);
		mappedByteBuffer.put(0, (byte) 'a');
		mappedByteBuffer.put(3, (byte) 'b');
		file.close();
	}

}
